package com.evil.common.application.dto.robot.action;

import com.evil.common.account.dto.user.UserEnterpriseDTO;
import com.evil.common.application.dto.robot.RobotConfigDTO;
import com.evil.common.application.enums.robot.RobotSourceTypeEnum;
import com.evil.common.application.enums.robot.RobotTriggerTypeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 机器人执行 请求实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RobotActionReqDTO extends RobotConfigDTO {

    /**
     * 触发动作 {@link RobotTriggerTypeEnum}
     */
    @NotNull(message = "触发动作不能为空")
    private Integer triggerType;

    /**
     * 是否立即保存
     */
    private Boolean saveNow;

    /**
     * 企业id
     */
    @NotNull(message = "enterpriseId not null")
    private Long enterpriseId;

    /**
     * 订单id
     */
    @NotNull(message = "订单id不能为空")
    private Long orderId;

    /**
     * 处理人
     */
    private UserEnterpriseDTO handler;

    /**
     * 应用key
     */
    @NotNull(message = "applicationId not null")
    private Long applicationId;

    /**
     * 应用key
     */
    @NotBlank(message = "applicationKey not null")
    private String applicationKey;

    /**
     * 记录应用层级
     */
    private List<String> logAppKeys;

    /**
     * 触发者
     */
    @NotNull(message = "triggerId not null")
    private Long triggerId;

    /**
     * 触发者
     */
    @NotBlank(message = "triggerName not null")
    private String triggerName;

    /**
     * 机器人类型
     */
    @NotNull(message = "robotSourceTypeEnum not null")
    private RobotSourceTypeEnum robotSourceTypeEnum;

    /**
     * 日志ID
     */
    private Long logId;

    public RobotActionReqDTO() {
        super();
        this.saveNow = false;
        this.logAppKeys = new ArrayList<>();
    }

    public String info() {
        return String.format("%s:%s(%s)，%s，是否立即保存：%s，当前订单：%s，应用key：%s，记录应用层级：%s",
                robotSourceTypeEnum.getName(), triggerName, triggerId, super.info(), saveNow, orderId, applicationKey, logAppKeys);
    }
}
